﻿Ext.define('SmartClient.utils.CommonFunctions',
   {
      statics:
         {
            setWindowSizeAndPosition: function (me, width, height, a, b, windowId)
            {
               var windowHeight = Ext.getBody().getViewSize().height,
                   addedProductsWindow = this,
                   addedProductsGrid = addedProductsWindow.down('gridpanel'),
                   addedProductsWindowInnerHeight = Ext.get(windowId + '-body').getHeight(),
                   addedProductsWindowVerticalBorder = addedProductsWindow.getHeight() - addedProductsWindowInnerHeight;

               addedProductsWindow.setHeight(addedProductsGrid.getHeight() + addedProductsWindowVerticalBorder);
               addedProductsWindow.setOverflowXY('hidden', 'hidden');
               if (addedProductsWindow.getHeight() > windowHeight)
               {
                  addedProductsWindow.setHeight(windowHeight);
                  addedProductsWindow.setOverflowXY('hidden', 'auto');
               }

               var addedProductsWindowInner = Ext.get(windowId + '-innerCt'),
                   addedProductsWindowInnerWidth = addedProductsWindowInner.getWidth(),
                   addedProductsWindowHorizontalBorder = addedProductsWindow.getWidth() - addedProductsWindowInnerWidth,
                   totalWidth = 0;

               Ext.each(addedProductsGrid.columns, function (column, index)
               {
                  totalWidth += column.width;
               });
               addedProductsGrid.setWidth(totalWidth);
               addedProductsWindow.setWidth(totalWidth + addedProductsWindowHorizontalBorder);
               addedProductsWindow.center();
               addedProductsWindow.setY(0);
            }
         }
   });